home *** CD-ROM | disk | FTP | other *** search
/ Isometric Game Programming with DirectX 7.0 / Isometric Game Programming.iso / source / chapter2 / isohex2_1 / isohex2_1.cpp next >
Encoding:
C/C++ Source or Header  |  2000-06-09  |  5.4 KB  |  209 lines

  1. /*****************************************************************************
  2. IsoHex2_1.cpp
  3. Ernest S. Pazera
  4. 12MAY2000
  5. Start a WIN32 Application Workspace, add in this file
  6. No other libs are required
  7. *****************************************************************************/
  8.  
  9. //////////////////////////////////////////////////////////////////////////////
  10. //INCLUDES
  11. //////////////////////////////////////////////////////////////////////////////
  12. #define WIN32_LEAN_AND_MEAN  
  13.  
  14. #include <windows.h>   
  15.  
  16. //////////////////////////////////////////////////////////////////////////////
  17. //DEFINES
  18. //////////////////////////////////////////////////////////////////////////////
  19. //name for our window class
  20. #define WINDOWCLASS "ISOHEX2"
  21. //title of the application
  22. #define WINDOWTITLE "IsoHex 2-1"
  23.  
  24. //////////////////////////////////////////////////////////////////////////////
  25. //PROTOTYPES
  26. //////////////////////////////////////////////////////////////////////////////
  27. bool Prog_Init();//game data initalizer
  28. void Prog_Loop();//main game loop
  29. void Prog_Done();//game clean up
  30.  
  31. //////////////////////////////////////////////////////////////////////////////
  32. //GLOBALS
  33. //////////////////////////////////////////////////////////////////////////////
  34. HINSTANCE hInstMain=NULL;//main application handle
  35. HWND hWndMain=NULL;//handle to our main window
  36.  
  37. //////////////////////////////////////////////////////////////////////////////
  38. //WINDOWPROC
  39. //////////////////////////////////////////////////////////////////////////////
  40. LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  41. {
  42.     //which message did we get?
  43.     switch(uMsg)
  44.     {
  45.     case WM_DESTROY://the window is being destroyed
  46.         {
  47.  
  48.             //tell the application we are quitting
  49.             PostQuitMessage(0);
  50.  
  51.             //handled message, so return 0
  52.             return(0);
  53.  
  54.         }break;
  55.     case WM_PAINT://the window needs repainting
  56.         {
  57.             //a variable needed for painting information
  58.             PAINTSTRUCT ps;
  59.             
  60.             //start painting
  61.             HDC hdc=BeginPaint(hwnd,&ps);
  62.  
  63.             /////////////////////////////
  64.             //painting code would go here
  65.             /////////////////////////////
  66.  
  67.             //end painting
  68.             EndPaint(hwnd,&ps);
  69.                         
  70.             //handled message, so return 0
  71.             return(0);
  72.         }break;
  73.     }
  74.  
  75.     //pass along any other message to default message handler
  76.     return(DefWindowProc(hwnd,uMsg,wParam,lParam));
  77. }
  78.  
  79.  
  80. //////////////////////////////////////////////////////////////////////////////
  81. //WINMAIN
  82. //////////////////////////////////////////////////////////////////////////////
  83. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
  84. {
  85.     //assign instance to global variable
  86.     hInstMain=hInstance;
  87.  
  88.     //create window class
  89.     WNDCLASSEX wcx;
  90.  
  91.     //set the size of the structure
  92.     wcx.cbSize=sizeof(WNDCLASSEX);
  93.  
  94.     //class style
  95.     wcx.style=CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  96.  
  97.     //window procedure
  98.     wcx.lpfnWndProc=TheWindowProc;
  99.  
  100.     //class extra
  101.     wcx.cbClsExtra=0;
  102.  
  103.     //window extra
  104.     wcx.cbWndExtra=0;
  105.  
  106.     //application handle
  107.     wcx.hInstance=hInstMain;
  108.  
  109.     //icon
  110.     wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION);
  111.  
  112.     //cursor
  113.     wcx.hCursor=LoadCursor(NULL,IDC_ARROW);
  114.  
  115.     //background color
  116.     wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
  117.  
  118.     //menu
  119.     wcx.lpszMenuName=NULL;
  120.  
  121.     //class name
  122.     wcx.lpszClassName=WINDOWCLASS;
  123.  
  124.     //small icon
  125.     wcx.hIconSm=NULL;
  126.  
  127.     //register the window class, return 0 if not successful
  128.     if(!RegisterClassEx(&wcx)) return(0);
  129.  
  130.     //create main window
  131.     hWndMain=CreateWindowEx(0,WINDOWCLASS,WINDOWTITLE, WS_BORDER | WS_SYSMENU | WS_VISIBLE,0,0,320,240,NULL,NULL,hInstMain,NULL);
  132.  
  133.     //error check
  134.     if(!hWndMain) return(0);
  135.  
  136.     //if program initialization failed, then return with 0
  137.     if(!Prog_Init()) return(0);
  138.  
  139.     //message structure
  140.     MSG msg;
  141.  
  142.     //message pump
  143.     for(;;)    
  144.     {
  145.         //look for a message
  146.         if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  147.         {
  148.             //there is a message
  149.  
  150.             //check that we arent quitting
  151.             if(msg.message==WM_QUIT) break;
  152.             
  153.             //translate message
  154.             TranslateMessage(&msg);
  155.  
  156.             //dispatch message
  157.             DispatchMessage(&msg);
  158.         }
  159.  
  160.         //run main game loop
  161.         Prog_Loop();
  162.     }
  163.     
  164.     //clean up program data
  165.     Prog_Done();
  166.  
  167.     //return the wparam from the WM_QUIT message
  168.     return(msg.wParam);
  169. }
  170.  
  171. //////////////////////////////////////////////////////////////////////////////
  172. //INITIALIZATION
  173. //////////////////////////////////////////////////////////////////////////////
  174. bool Prog_Init()
  175. {
  176.     //rectangle into which we will place the desired client RECT
  177.     RECT rc;
  178.     SetRect(&rc,0,0,640,480);
  179.  
  180.     //get the window rect based on our style and extended style
  181.     AdjustWindowRectEx(&rc,WS_BORDER | WS_SYSMENU | WS_CAPTION | WS_VISIBLE,FALSE,0);
  182.  
  183.     //use movewindow to resize the window
  184.     MoveWindow(hWndMain,0,0,rc.right-rc.left,rc.bottom-rc.top,TRUE);
  185.  
  186.     return(true);//return success
  187. }
  188.  
  189. //////////////////////////////////////////////////////////////////////////////
  190. //CLEANUP
  191. //////////////////////////////////////////////////////////////////////////////
  192. void Prog_Done()
  193. {
  194.     //////////////////////////
  195.     //clean up code goes here
  196.     //////////////////////////
  197. }
  198.  
  199. //////////////////////////////////////////////////////////////////////////////
  200. //MAIN GAME LOOP
  201. //////////////////////////////////////////////////////////////////////////////
  202. void Prog_Loop()
  203. {
  204.     ///////////////////////////
  205.     //main game logic goes here
  206.     ///////////////////////////
  207. }
  208.  
  209.